import { addfav, removefav, addlike, removelike } from '@/api/api'
export default {
    addFav() {
        let articleList2 = JSON.parse(localStorage.getItem("articleList2"));
        let { uid: user_id } = localStorage;
        let article_id = articleList2._id;
        let { is_fav } = this

        if (!is_fav) {
            addfav(user_id, article_id).then(res => {
                this.$toast(res.data.msg)
                this.is_fav = true
            })

        } else {
            removefav(user_id, article_id).then(res => {
                this.$toast(res.data.msg)
                this.is_fav = false
            })
        }
    },
    addlike() {
        let articleList2 = JSON.parse(localStorage.getItem("articleList2"));
        let { uid: user_id } = localStorage;
        let article_id = articleList2._id;
        let { is_like } = this
        if (!is_like) {
            addlike(user_id, article_id).then(res => {
                this.$toast(res.data.msg)
                this.is_like = true
            })
        } else {
            removelike(user_id, article_id).then(res => {
                this.$toast(res.data.msg)
                this.is_like = false
            })
        }
    }



}